import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../model/order/UserOrderItem.dart';

class CommodityCard extends StatefulWidget {
  const CommodityCard({required Key key, required this.item}) : super(key: key);

  final UserOrderItem item;

  @override
  _CommodityCardState createState() => _CommodityCardState();
}

class _CommodityCardState extends State<CommodityCard> {
  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            SizedBox(
              width: 80.w,
              height: 80.w,
              child: ClipRRect(
                borderRadius: BorderRadius.circular(8.r),
                child: CachedNetworkImage(
                  fit: BoxFit.cover,
                  imageUrl: '${widget.item.commoditySkuImage}',
                  placeholder: (context, url) => SizedBox(
                    width: 80.w,
                    height: 80.w,
                    child: Image.asset(
                      "assets/images/app_icon1024.png",
                      fit: BoxFit.cover,
                    ),
                  ),
                  errorWidget: (context, url, error) => SizedBox(
                    width: 80.w,
                    height: 80.w,
                    child: Image.asset(
                      "assets/images/app_icon1024.png",
                      fit: BoxFit.cover,
                    ),
                  ),
                ),
              ),
            ),
            SizedBox(width: 12.w),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Padding(padding: EdgeInsets.only(bottom: 6.h)),
                  Text(
                    widget.item.commodityName ?? "",
                    style: TextStyle(
                      fontFamily: "PingFang SC",
                      fontWeight: FontWeight.w700,
                      fontSize: 14.sp,
                      color: const Color(0xFF262626),
                    ),
                    maxLines: 2,
                    overflow: TextOverflow.ellipsis,
                  ),
                  SizedBox(height: 4.h),
                  Text(
                    widget.item.commoditySkuName ?? "",
                    style: TextStyle(
                      fontFamily: "PingFang SC",
                      fontSize: 12.sp,
                      color: const Color(0xFF8C8C8C),
                    ),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  ),
                  SizedBox(height: 8.h),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        "￥${widget.item.commoditySkuTotalPrice ?? 0}",
                        style: TextStyle(
                          fontFamily: "PingFang SC",
                          fontSize: 14.sp,
                          fontWeight: FontWeight.w700,
                          color: const Color(0xFFF55F4E),
                        ),
                      ),
                      Text(
                        "x${widget.item.commoditySkuNum ?? 0}",
                        style: TextStyle(
                          fontFamily: "PingFang SC",
                          fontSize: 12.sp,
                          fontWeight: FontWeight.w500,
                          color: const Color(0xFF8C8C8C),
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
      ],
    );
  }
}
